package com.g001.match3;

import java.io.IOException;

import org.lwjgl.input.Keyboard;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;

import com.g001.service.BattleArenaService;
import com.g001.service.BattleZoneService;
import com.g001.service.Match3IblockService;
import com.g1.screens.enumerations.GameStates;


public class Match3 extends BasicGameState   {
	
	private Match3IblockService service = new Match3IblockService();
	private BattleZoneService battleZoneService = new BattleZoneService();
	private BattleArenaService battleArenaService = new BattleArenaService();
	
	@Override
	public void init(GameContainer container, StateBasedGame game)
			throws SlickException {
		try {
			battleZoneService.init(container, game);
			battleArenaService.init(container, game);
			service.initMatch3Game(battleArenaService.getPlayer(), battleArenaService.getEnemy());
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void render(GameContainer container, StateBasedGame game, Graphics g)
			throws SlickException {
		battleZoneService.render(container,game,g);
		service.render(container,game,g);	
		battleArenaService.render(container, game, g);
	}

	@Override
	public void update(GameContainer container, StateBasedGame game, int delta)
			throws SlickException {
		battleZoneService.update(container, game, delta);
		service.update(container, game, delta);
		battleArenaService.update(container, game, delta);
		if(container.getInput().isKeyPressed(Keyboard.KEY_ESCAPE)){
			container.exit();
		}
		
	}

	@Override
	public int getID() {
		return GameStates.MATCH3.getId();
	}
	

}
